﻿using MediatR;
using RBAC.MaHaiBo.API.Application.Command.SlaughterCommand;
using RBAC.MaHaiBo.Service.TraceabilityService;

namespace RBAC.MaHaiBo.API.Application.CommandHandlers.SlaughterHandler
{
    public class AddSlaughterFirmCommandHandler : IRequestHandler<AddSlaughterFirmCommand, int>
    {
        /// <summary>
        /// 屠宰服务层
        /// </summary>
        ISlaughterService service;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service">屠宰服务层</param>
        public AddSlaughterFirmCommandHandler(ISlaughterService service)
        {
            this.service = service;
        }

        public async Task<int> Handle(AddSlaughterFirmCommand request, CancellationToken cancellationToken)
        {
            return await service.AddSlaughterFirm(new  Entity.Firm()
            {
                Firmid = request.Firmid,
                provinceId = request.provinceId,
                cityId = request.cityId,
                countyId = request.countyId,
                address = request.address,
                EstablishTime = request.EstablishTime,
                FirmSynopsis = request.FirmSynopsis,
                LOT = request.LOT,
                SlaughterFirmName = request.SlaughterFirmName,
                FirmName = request.FirmName,
                ProductionPermit = request.ProductionPermit,
                farmFirm = request.farmFirm,
                principal = request.principal,
                NumberOfFields = request.NumberOfFields,
                Uid = request.Uid,
                AddName = request.AddName,
                AddTime = request.AddTime,
                UpdName = request.UpdName,
                UpdTime = request.UpdTime,
                DelName = request.DelName,
                DelTime = request.DelTime
            });
        }
    }
}
